package share

import (
	"errors"
	"jgt-oper/src/bll"
	"jgt-oper/src/context"
)

// EnterpriseVisit 来访信息管理
type EnterpriseVisit struct {
	EnterpriseVisitBll *bll.EVisit `inject:""`
}

// Get 精确查询数据
func (a *EnterpriseVisit) Get(ctx *context.Context) error {
	ctx.WriteOperateLog("EnterpriseVisit.Get", "分享平台-企业来访-二维码查询")
	visitID := ctx.Param("id")
	if visitID == "" {
		return ctx.ResErrBadRequest(errors.New("id参数错误"))
	}
	visitItem, err := a.EnterpriseVisitBll.Get(visitID)
	if err != nil {
		return ctx.ResErrInternalServer(err)
	}
	if visitItem == nil {
		return ctx.ResErrInternalServer(errors.New("来访记录信息出现空指针"))
	}
	resultMap := make(map[string]interface{})
	resultMap["record_id"] = visitItem.RecordID
	resultMap["personnel_name"] = visitItem.PersonnelName
	resultMap["start_time"] = visitItem.StartTime
	resultMap["end_time"] = visitItem.EndTime

	resultMap["code_url"] = "www.xiaoyuanjijiehao.com"

	return ctx.ResSuccess(resultMap)
}
